﻿using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using Product_1_1.ViewModels;
using ReactiveUI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Product_1_1
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class Product_1_1_View : UserControl, IInputView, IViewFor<Product_1_1_ViewModel>
    {
        ServiceReference1.Container context = new ServiceReference1.Container(new Uri("http://localhost:1179/odata"));
        private InputPresenter _presenter;
        private readonly IUnityContainer container;
        private readonly IRegionManager rManager;


        public event EventHandler Result;

        public Product_1_1_View()
        {
            InitializeComponent();
            
            ViewModel = new Product_1_1_ViewModel();

            //this.Bind(ViewModel, vm => vm.Quantity, v => v.Product_Quantity.Text);
            //this.Bind(ViewModel, vm => vm.Region1, v => v.vita500DataGrid.DataContext);

            //this.BindCommand(ViewModel, vm => vm.Initialize, v => v.computed1);

            this.vita500ListView.ItemsSource = (IEnumerable)context.Vita500;

            this.materialsListView.ItemsSource = from kkk in context.Materials
                                                 where kkk.Pro_Id == 2
                                                 select kkk;

            this.materialsListView1.ItemsSource =
                                                from kkk in context.Materials
                                                where kkk.Pro_Id != 2
                                                select kkk;

            this.LotNumber.ItemsSource = from kkk in context.LotNumbers
                                         where kkk.Pro_Id == 2
                                         select new
                                         {
                                             PM_LotNumber = kkk.Lot_LotNumber
                                         };

        }

        public Product_1_1_View(InputPresenter presenter, IUnityContainer c, IRegionManager r) : this()
        {
            _presenter = presenter;
            _presenter.View = this;

            container = c;
            rManager = r;
        }
        public string Number
        {
            get
            {
                return this.LotNumber.Text.ToString();
            }
        }

        //public string Year
        //{
        //    get
        //    {
        //        return this.YearCbx.Text.ToString();
        //    }
        //}

        //public string Month
        //{
        //    get
        //    {
        //        return this.MonthCbx.Text.ToString();
        //    }
        //}

        //public string Day
        //{
        //    get
        //    {
        //        return this.DayCbx.Text.ToString();
        //    }
        //}

        public string Quantity
        {
            get
            {
                return this.Product_Quantity.Text.ToString();
            }
        }

        public Product_1_1_ViewModel ViewModel { get; set; }

        object IViewFor.ViewModel
        {
            get
            {
                return ViewModel;
            }

            set
            {
                ViewModel = value as Product_1_1_ViewModel;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Vita500ListView2.ItemsSource = from kkk in context.Vita500
                                               select new
                                               {

                                                   Vita_Name = kkk.Vita_Name,
                                                   Vita_Quantity = kkk.Vita_Quantity * (Convert.ToInt32(this.Product_Quantity.Text))
                                               };
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            Uri viewNav = new Uri("Product_2_1_View", UriKind.Relative);
            rManager.RequestNavigate(RegionNames.MainContentRegion, viewNav);

            Result(this, null);

        }

      
    }
}
